/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import java.util.ArrayList;
import java.util.Calendar;

public class Book extends LendReserveItem {
    private ISBN _isbn;
    private Publisher _publisher;
    private Calendar _publishingYear;
    private ArrayList<Author> _authors;

    /**
     * Constructor
     * 
     * @param title Booktitle
     * @param isbn ISBN
     * @param author Author of the book
     * @param publisher Publisher of the book
     * @param year
     * @param desc 
     */
    public Book(String title, Author author, ISBN isbn, Publisher publisher, Calendar publishingYear, String desc) {
        super(title, desc);
        _isbn = isbn;
        _publisher = publisher;
        _publishingYear = publishingYear;
        _authors = new ArrayList<Author>();
        _authors.add(author);
    }
    
    /**
     * Specific getter's
     */
    public ISBN getISBN() {
        return _isbn;
    }
    public Author[] getAuthors() {
        Author[] authors = new Author[_authors.size()];
        return _authors.toArray(authors);
    }
    public Publisher getPublisher() {
        return _publisher;
    }
    public Calendar getPublishingYear() {
        return _publishingYear;
    }
    
    @Override
    public String toString() {
        StringBuilder rv = new StringBuilder();
        rv.append("(");
        rv.append(super.getId());
        rv.append(") ");
        rv.append(_title);
        for (Author a : _authors) {
            rv.append(", ");
            rv.append(a.getAuthorName());
        }
        rv.append(", ");
        rv.append(_publisher.getName());
        rv.append(" (");
        rv.append(_publishingYear);
        rv.append(")");
        return rv.toString();
    }
    
    /**
     * Adds an additional author
     * @param a author
     */
    public void addAuthor(Author a) {
        _authors.add(a);
    }
}
